import { LinValidator, Rule } from "../code/lin-validator-v2"
import TemplateType from "../sql/module/factory/template_type"

export class TypeValidator extends LinValidator {
    constructor() {
        super()
        this.name = [
            new Rule('isLength', '材料类型名字数小于4', { max: 4 })
        ]
    }
}

export class StoreValidator extends LinValidator {
    constructor() {
        super()
        this.name = [
            new Rule('isLength', '名字数小于50', { max: 50 })
        ]
    }
    async validateTypeId(vals: { body: { TemplateTypeId: any } }) {
        const id = vals.body.TemplateTypeId
        if (!id) throw new Error('材料类型不存在')
        const material = await TemplateType.findOne({
            where: { id }
        })
        if (!material) throw new Error('材料类型不存在')
    }
}
export class SetImageValidator extends LinValidator {
    constructor() {
        super()
        this.ImgTemplateId = [new Rule('isInt', '图片id有误')]
        this.MaterialId = [new Rule('isInt', '材料id有误')]
        this.offsetX = [new Rule('isInt', '图片设置x位置有误')]
        this.offsetY = [new Rule('isInt', '图片设置y位置有误')]
    }
}
export class GetImageValidator extends LinValidator {
    constructor() {
        super()
        this.ImgTemplateId = [new Rule('isInt', '图片id有误')]
        this.MaterialId = [new Rule('isInt', '材料id有误')]
    }
}
export class GetImagesValidator extends LinValidator {
    constructor() {
        super()
        this.ImgTemplateId = [new Rule('isInt', '图片id有误')]
        this.TemplateId = [new Rule('isInt', '模版id有误')]
    }
}